<template>
  <div class="body1" style="padding-top:10px;">
    <div class="form_select">
      <div>
          <el-input class="select_input" size="small" v-model="name" placeholder="产品名称"></el-input>
          <el-select class="select_option" size="small" v-model="cate_name" placeholder="请选择">
            <el-option
              v-for="item in cate"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
          <el-button type="primary"  size="small" @click="search">搜索</el-button>
      </div>
      <div class="select_right">
          <el-button type="primary"  size="small" @click="cateClick('goodsCheckShow')">仓库盘点</el-button>
          <el-dropdown>
            <el-button type="primary" size="small">
              更多操作<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="cateClick('cateShow')">产品分类</el-dropdown-item>
              <el-dropdown-item @click.native="cateClick('cateAddShow')">添加分类</el-dropdown-item>
              <el-dropdown-item @click.native="exportExcel(1)">导出当页</el-dropdown-item>
              <el-dropdown-item @click.native="exportExcel(2)">导出全部</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-button type="primary"  size="small" @click="add">新增产品</el-button>
      </div>
    </div>
    <goodsTable :list="list" @func="editTrue"></goodsTable>
    <goodsAdd :show="addShow" @func="change"></goodsAdd>
    <goodsEdit :show="editShow" :item="item" :tags="tags" @func="change"></goodsEdit>
    <goodsCate :show="cateShow" :cate="cateArr" @func="change"></goodsCate>
    <cateAdd :show="cateAddShow" @func="change"></cateAdd>
    <goodsCheck :show="goodsCheckShow" :list="list"  @func="change"></goodsCheck>
    </div>
   </div>


</template>
 
<script>
import goodsAdd from "./add"
import goodsEdit from "./edit"
import goodsTable from "./table"
import goodsCate from "./cate"
import cateAdd from "./cateAdd"
import goodsCheck from "./goodsCheck"
import {excelExport} from "../../public/excelExport"
export default {
  name: "Goods",
  data() {
    return {
      list:[],
      name:'',
      cate:[
        {id:0,name:'全部'}
      ],
      cate_name:'',
      item:{},
      addShow:false,
      editShow:false,
      cateShow:false,
      cateAddShow:false,
      goodsCheckShow:false,
      tags:[],
      cateArr:[]
    };
  },
  components: {
    "goodsAdd": goodsAdd,
    "goodsEdit": goodsEdit,
    "goodsTable": goodsTable,
    "goodsCate":goodsCate,
    "cateAdd":cateAdd,
    "goodsCheck":goodsCheck
  },
  created: function() {
    this.getList()
    this.getCate()
  },
  methods: {
    goadd:function(){
      this.$router.push({path : "/add"})
    },
    getList:function() {
      var data = {
        store_id:localStorage.getItem('store_id'),
        name:this.name,
        cid:this.cate_name
      }
      var that = this
      this.$get('goods/all',data).then((res) => {
        that.list = res.data
      })
    },
    getCate:function(){
      var data = {store_id:localStorage.getItem('store_id')}
      var that = this
      this.$get('goods/cate',data).then((res) => {
        var cate = that.cate
        that.cate = cate.concat(res.data)
        that.cateArr = res.data
      })
    },
    search:function(){
      this.getList()
    },
    add:function(){
      this.addShow = true
    },
    change:function(data){
      this[data.key] = false
      if(data.key == 'cateAddShow'){
        this.cate = []
        this.getCate()
      }
      if(data.type == 1){
        this.getList()
      }
    },
    editTrue:function(data){
      this[data.key] = true
      this.item = data.item
      this.tags = this.item.tag.split(',')
    },
    cateClick:function(key){
      this[key] = true
    },
    exportExcel:function() {
      let title = '商品信息表'
      excelExport(title)
      return false;
    }
}
};
</script>
<style>
</style>